package cn.tjjcy.common;

import lombok.Data;

import java.util.Map;
import java.util.Objects;

@Data
public class GzResult {

    //规则判断
    private Boolean gzResult;

    private Map<String, Object> gzMap;

    private String gzSql;

    private String gzErrorReason;


    //保存结果
    private String resultSql;

    private Boolean result;


    public static GzResult judgeFail(String errorReason, String gzSql) {
        GzResult gzRe = new GzResult();
        gzRe.setGzResult(false);
        gzRe.setGzErrorReason(errorReason);
        gzRe.setGzSql(gzSql);
        return gzRe;
    }

    public static GzResult judgeFail(String errorReason, String gzSql, Map<String, Object> gzMap) {
        GzResult gzRe = new GzResult();
        gzRe.setGzResult(false);
        gzRe.setGzErrorReason(errorReason);
        gzRe.setGzSql(gzSql);
        return gzRe;
    }

    public static GzResult judgeSuccess(Map<String, Object> gzMap, String gzSql) {
        GzResult gzRe = new GzResult();
        gzRe.setGzResult(true);
        gzRe.setGzSql(gzSql);
        gzRe.setGzMap(gzMap);
        gzRe.setGzErrorReason("触发规则");
        return gzRe;
    }


    public String getBmsah() {
        if (gzMap == null) {
            return null;
        }
        String bmsah = null;
        Object object = gzMap.get("bmsah");
        if (Objects.isNull(object)) {
            bmsah = gzMap.get("BMSAH").toString();
        } else {
            bmsah = object.toString();
        }
        return bmsah;
    }

}
